package components.contorls.superClass
{
    import components.core.UIComponent;
    import components.utils.EventListenerUtil;

    import flash.display.DisplayObject;
    import flash.events.Event;
    import flash.events.MouseEvent;

    [Event(name = "change", type = "flash.events.Event")]
    public class BaseComboBox extends BaseDropDownList
    {
        private var _text:String = "";

        public function BaseComboBox()
        {
            super();

            EventListenerUtil.addEventListener(textInput, Event.CHANGE, textInput_changeHandler);
        }

        /***************************************
         *
         * 显示对象声明
         *
         * **************************************/

        public function get textInput():BaseTextInput
        {
            return getChildByName("textInputSkin") as BaseTextInput;
        }

        /***************************************
         *
         * 验证
         *
         * **************************************/

        protected override function commitProperties():void
        {
            super.commitProperties();

            if (text != null)
                textInput.text = text;
            else
                textInput.text = "";
        }

        protected override function measureSizes():Boolean
        {
            if (super.measureSizes())
            {
                textInput.width = width - 4 - 22.05;
                return true;
            }

            return false;
        }

        protected override function updateDisplayList():void
        {
            super.updateDisplayList();
        }

        /***************************************
         *
         * 组件定义
         *
         * **************************************/


        /***************************************
         *
         * 其他代码
         *
         * **************************************/
        public function get text():String
        {
            return _text;
        }

        public function set text(value:String):void
        {
            _text = value;
            invalidate();
        }

        protected function textInput_changeHandler(event:Event):void
        {
            selectedIndex = -1;
            _text = textInput.text;

            dispatchEvent(new Event(Event.CHANGE));

        }

        override public function set selectedItem(value:Object):void
        {
            text = String(value);
            super.selectedItem = value;
        }

        public override function set focusComp(value:UIComponent):void
        {
            super.focusComp = value;
            textInput.focusComp = focusComp;
        }

        public override function destroy():void
        {
            super.destroy();
            _text = null;
        }

        public override function validateNow():void
        {
            super.validateNow();
            textInput.validateNow();
        }
    }
}
